﻿Imports System.Windows.Forms

Public Class frmInputBox

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Public Shared Function ShowInputBox(Prompt As String, Optional Title As String = "", Optional DefaultResponse As String = "") As String
        With New frmInputBox
            .lblPrompt.Text = Prompt
            If Title = "" Then .Text = Application.ProductName Else .Text = Title
            .txtResponse.Text = DefaultResponse
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                Return .txtResponse.Text
            Else
                Return ""
            End If
        End With
    End Function

    Private Sub txtResponse_KeyDown(sender As Object, e As KeyEventArgs) Handles txtResponse.KeyDown
        If e.KeyCode = Keys.Return And e.Control Then
            btnOK.PerformClick()
        End If
    End Sub

    Private Sub txtResponse_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtResponse.KeyPress

    End Sub
End Class
